﻿#include "StructEdit.h"
#include "ui_StructEdit.h"

StructEdit::StructEdit(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::StructEdit)
{
    ui->setupUi(this);
    init();
}

StructEdit::~StructEdit()
{
    delete ui;
}

/**
 * @brief StructEdit::slot_ShowStructDisplay 显示结构体界面
 * @param index 结构体界面索引
 */
void StructEdit::slt_ShowStructDisplay(const int &index)
{
    emit sgl_ShowStructDisplay(2);
}

/**
 * @brief StructEdit::on_lineEdit_search_textChanged 搜索文本改变
 * @param arg1 搜索文本
 */
void StructEdit::on_lineEdit_search_textChanged(const QString &arg1)
{
    ui->tableView_Struct->setFilterRegExp(arg1);
}

/**
 * @brief StructEdit::on_pushButton_addStruct_clicked 添加结构体
 */
void StructEdit::on_pushButton_addStruct_clicked()
{
    int structId;
    QString structName;
    emit sgl_AddStruct(structId,structName);
    ui->tableView_Struct->addRowData(structId,QVector<QVariant>()<<structId<<structName<<0);
    //    //设置字偏移和位偏移列为不可编辑
    ui->tableView_Struct->setCellEditabled(structId,2,false);
}

/**
 * @brief StructEdit::on_pushButton_deleteStruct_clicked 删除结构体
 */
void StructEdit::on_pushButton_deleteStruct_clicked()
{
    QVariant rowId = ui->tableView_Struct->getSelectRowId();
    ui->tableView_Struct->deleteRow(rowId);
    emit sgl_DeleteStruct(rowId); //rowId即主题Id
}

/**
 * @brief StructEdit::on_pushButton_select_clicked 选择结构体
 */
void StructEdit::on_pushButton_select_clicked()
{

}

/**
 * @brief StructEdit::initStructTableView 初始化结构体表格
 */
void StructEdit::init()
{
    //设置窗口为模态
    this->setWindowModality(Qt::ApplicationModal);
    //添加表头
    ui->tableView_Struct->addColumn("结构体Id");
    ui->tableView_Struct->addColumn("结构体名称");
    ui->tableView_Struct->addColumn("长度");
    //设置表格视图属性
    ui->tableView_Struct->setSelectionBehavior(QAbstractItemView::SelectRows);
    //建立连接
    connect(ui->widget_signal,&SignalEdit::sgl_ShowStructDisplay,this,&StructEdit::slt_ShowStructDisplay);
//    connect(ui->tableView_Struct,&StructEdit::sgl_LoadSignalInfo,ui->widget_signal,&SignalEdit::slt_LoadSignalInfo);
}

